<template>
  <el-tabs type="border-card" @tab-remove="removeTab" :closable="true">
    <el-tab-pane :label="baseInfo.name">
<!--    <topNavbar :content="baseInfo.name" :title="content" :path="path"></topNavbar>-->
   <jsPage
   :form="baseInfo"
   :js="js"
   :ys="ys"
   :costList="costList"
   :newJs="newJs"
   :is_hidden="is_hidden"
   :disabled="disabled"
   :is_show="is_show"
   :is_show_btn="is_show_btn"
   :btn="btn"
   @changeJs="changeJs"
   @changeFile="changeFile"
   @commit="editProjectYs"
   style="margin-top: 10px;"
   >
   <template #js1>
     <el-form-item label="项目名称">
       <el-input v-model="baseInfo.name" disabled></el-input>
     </el-form-item>
   </template>


 </jsPage>
    <spForm :form="spform" v-if="is_hidden"></spForm>
    </el-tab-pane>
  </el-tabs>
</template>

<script>
  import {getJsDetail,editProjectJs} from '@/apilist/Project'
  import jsPage from "./jsPage";
  import baseInfo from "../common/baseInfo";
  import spForm from "../common/spForm";
  import topNavbar from "../common/topNavbar";
    export default {
        name: "project_edit_js",
        data(){
            return {
                id: 0,
                baseInfo:'',
                js: '',
                ys: '',
                costList:'',
                newJs: '',
                disabled: '',
                is_hidden: false,
                is_show_btn: false,
                is_show: '',
                btn: '',
                spform:{
                    note:'',//审批备注
                    newData:'',
                    type: 'js',
                },
                content: '结算数据',
                path: '/project_list',
            }
        },
        components: {jsPage,baseInfo,spForm,topNavbar},
        methods: {

            changeJs(js,new_js,cost_list){
                console.log(js,'js')
                this.js = js
                this.newJs = new_js
                this.costList = cost_list
            },
            //修改上传文件
            changeFile(file_list,name){
                this.js[name] = file_list
            },
            //修改结算
              editProjectYs(is_save){
                let params = {
                    xmid: this.baseInfo.id,
                    js: this.js,
                    costList: this.costList,
                    newJs: this.newJs,
                    is_save: is_save,
                    id: this.id,
                    type: 2,
                }

                 editProjectJs(params).then(res =>{
                   this.$message({
                     type:"success",
                     message: res.msg,
                     onClose:()=>{
                       this.getJsData()
                     },
                   });
                 });

            },
          removeTab(){
            this.$router.push({
              path: this.path,
              query: {
                tab: 2
              }
            });
          },

          getJsData(){
            getJsDetail({id: this.id}).then(res => {
              console.log(res.data)
              this.baseInfo = res.data.baseInfo
              this.js = res.data.js
              this.ys = res.data.ys
              this.costList = res.data.costList
              this.newJs = res.data.newJs
              this.disabled = res.data.disable
              this.is_hidden = res.data.hidden
              this.btn = res.data.btn
              this.spform.newData = res.data
              this.is_show = res.data.is_show
              this.is_show_btn = res.data.is_show_btn

            })
          },





        },

        mounted() {
            this.id = this.$route.query.id
            this.getJsData();
        }
    }
</script>

<style scoped>

</style>
